let box = document.querySelector(".box");
let userName = document.querySelector("#un");
let password = document.querySelector("#mm");
let sub = document.querySelector("#sub");
let reg = document.querySelector("#reg");
let ts = document.querySelector(".ts");
let mmts = document.querySelector(".mmts");
let headerImg = document.querySelector('#headerImg')
//非空判断
function judgeIsNull() {
    userName.addEventListener("blur", function () {
        if (userName.value == "") {
            ts.classList.add("active");
            return;
        } else {
            ts.classList.remove("active");
        }
    });
    password.addEventListener("blur", function () {
        // 注册密码格式验证，验证规则 ： 密码必须是大写字母开头，英文字母数字和组合，至少8位。
        let passd = password.value;
        let zzmm = /^[A-Z][[a-z]|[0-9]]{7+}/;
        let isTrue = zzmm.test(passd);
        console.log(isTrue);
        if (password.value == "" || isTrue == false) {
            mmts.classList.add("active");
            return;
        } else {
            mmts.classList.remove("active");
        }
    });
}
judgeIsNull();
//注册功能
function submit() {
    sub.addEventListener("click", function () {
        let name = userName.value;
        let psd = password.value;
        let headerImgs = headerImg.value
        myPromise({
            method: 'post',
            url: 'http://api.yuguoxy.com/api/member/add',
            data: {
                username: name,
                password: psd,
                headerimg: headerImgs
            }
        }).then(function (data) {
            if (data.resultCode == 1) {
                alert('注册成功！')
            } else {
                alert('注册失败')
            }
        })
        userName.value = "";
        password.value = "";
        headerImg.value = ""


    });
}

function register() {
    reg.addEventListener("click", function () {
        window.location.href = "login.html";
    });
}
register();
submit();